package gv.trans.util;

import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

public class Utils {
	
	private static BaseGameActivity activity;

	public static int toScreenX(int perc) {
		return (Global.CAMERA_WIDTH * perc) / 100;
	}

	public static int toScreenY(int perc) {
		return (Global.CAMERA_HEIGHT * perc) / 100;
	}
	
	public static TiledTextureRegion getTiledRegion(String asset, int tiles){
		Texture texture = null; TiledTextureRegion region = null;
		
		boolean dim_ok = false; int i = 2;
		while(!dim_ok){
			dim_ok = true; i=i*2;
			try{
				texture = new Texture(i, i, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
				region = TextureRegionFactory.createTiledFromAsset(texture, activity, asset, 0, 0, tiles, 1);
				activity.getEngine().getTextureManager().loadTextures(texture);
			}
			catch(Exception iae){
				dim_ok = false;
				continue;
			}
		}
		return region;
	}

	public static void setActivity(BaseGameActivity activity) {
		Utils.activity=activity;
		
	}

}
